package com.markerhub.mapper;

import com.markerhub.entity.TeachingStudentLearning;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface TeachingStudentLearningMapper extends BaseMapper<TeachingStudentLearning> {

    @Select("SELECT " +
            "    ms.stu_name as studentName, " +
            "    COALESCE(tsl.finished_status, '0') as finishedStatus, " +
            "    tsl.finished_time as finishedTime " +
            "FROM m_teaching_student_in_class tsic " +
            "JOIN m_manager_student ms ON tsic.student_id = ms.id " +
            "LEFT JOIN m_teaching_student_learning tsl ON tsic.id = tsl.stu_in_class_id " +
            "    AND tsl.unit_id = #{unitId} " +
            "WHERE tsic.class_id = #{classId} " +
            "ORDER BY tsl.finished_status DESC, ms.stu_name")
    List<Map<String, Object>> getStudentProgress(@Param("unitId") Integer unitId,
                                                 @Param("classId") Integer classId);
}
